home *** CD-ROM | disk | FTP | other *** search
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "MyMovies.h"
-
-
-
- OSErr MyPrepareDestMovie(DocumentPtr theDocument)
- {
- long keyFrameRate,compressedFrameSize;
- short frameRate,width,height,i;
- CodecComponent theCodec;
- OSErr err;
- FSSpec theFSSpec;
- TimeScale dstTimeScale;
- TimeValue duration;
- CodecQ spatialQuality;
- Str255 movieName = "\p.mov";
-
- keyFrameRate = 1; // Every frame must be a key frame. If not we'll get garbage
- // around the edges of our objects when we rotate them. Quicktime
- // only refreshes key frames completely.
- theCodec = anyCodec; // We'll use what's there
- spatialQuality = codecHighQuality; // and make it pretty.
- frameRate = 10; // This can be any value.
- dstTimeScale = 600; // This can be any multiple of framerate
- duration = 60;
-
- width = theDocument->theWindow->portRect.right - theDocument->theWindow->portRect.left;
- height = theDocument->theWindow->portRect.bottom - theDocument->theWindow->portRect.top;
-
- theFSSpec = theDocument->theFileSpec;
- for(i = 1; i <= movieName[0];i++)
- theFSSpec.name[i+theFSSpec.name[0]] = movieName[i];
- theFSSpec.name[0] += 4;
-
- err = CreateMovieFile(&theFSSpec, 'TVOD', 0, createMovieFileDeleteCurFile,
- &theDocument->dstMovieRefNum, &theDocument->dstMovie);
- if (err)
- return err;
-
- theDocument->dstTrack = NewMovieTrack(theDocument->dstMovie,
- ((long)width) << 16, ((long)height) << 16, 0);
- theDocument->dstMedia = NewTrackMedia(theDocument->dstTrack,
- VideoMediaType, dstTimeScale, 0, 0);
- err = BeginMediaEdits(theDocument->dstMedia);
- if (err)
- return err;
-
- err = GetMaxCompressionSize(theDocument->drawContextOffscreen->portPixMap,
- &theDocument->drawContextOffscreen->portRect, 32, spatialQuality,
- theDocument->theCodecType, theCodec, &compressedFrameSize);
- if (err)
- return err;
-
- theDocument->compressedData = NewHandle(compressedFrameSize);
- theDocument->compressedDataPtr = StripAddress(*(theDocument->compressedData));
- HLock(theDocument->compressedData);
- theDocument->idh = (ImageDescriptionHandle)NewHandle(4);
-
- return err;
- }
-
-
- OSErr MyAddImageToMovie(DocumentPtr theDocument)
- {
- CodecQ spatialQuality;
- TimeValue duration,currentTime;
- OSErr err;
-
- spatialQuality = codecHighQuality;
- duration = 60;
-
- LockPixels(theDocument->drawContextOffscreen->portPixMap);
- CompressImage(theDocument->drawContextOffscreen->portPixMap,
- &theDocument->drawContextOffscreen->portRect,spatialQuality,
- theDocument->theCodecType,theDocument->idh,theDocument->compressedDataPtr);
- UnlockPixels(theDocument->drawContextOffscreen->portPixMap);
-
- err = AddMediaSample(theDocument->dstMedia,theDocument->compressedData,0,
- (**(theDocument->idh)).dataSize,duration,
- (SampleDescriptionHandle)theDocument->idh,1,0,¤tTime);
-
- return err;
- }
-
- void MyCloseDestMovie(DocumentPtr theDocument)
- {
- OSErr err;
- short resID;
-
- err = EndMediaEdits(theDocument->dstMedia);
- if (err)
- goto cleanup;
-
- InsertMediaIntoTrack(theDocument->dstTrack,0,0,
- GetMediaDuration(theDocument->dstMedia),1L<<16);
- err = GetMoviesError();
- if (err)
- goto cleanup;
-
- resID = 128;
- err = AddMovieResource(theDocument->dstMovie,theDocument->dstMovieRefNum,
- &resID,(unsigned char *)"\pMovie 1");
-
- cleanup:
- if (theDocument->compressedData) {
- HUnlock((Handle)theDocument->compressedData);
- DisposeHandle(theDocument->compressedData);
- }
-
- if (theDocument->dstMovieRefNum)
- CloseMovieFile(theDocument->dstMovieRefNum);
-
- if (theDocument->dstMovie)
- DisposeMovie(theDocument->dstMovie);
-
- if (theDocument->idh)
- DisposeHandle((Handle)theDocument->idh);
- }